
<template>
  <div>
    <!-- 添加商品 -->
    <el-button
      @click='go2goodAdd'
      plain
      type='success'
    >添加商品</el-button>
    <!-- 表格 -->
    <el-table :data="goodsData">
      <el-table-column type='index'>
      </el-table-column>
      <el-table-column
        prop="goods_name"
        label="商品名称"
        width="180"
      >
      </el-table-column>
      <el-table-column
        prop="goods_price"
        label="商品价值"
        width="180"
      >
      </el-table-column>
      <el-table-column
        prop="goods_number"
        label="商品数量"
      >
      </el-table-column>
      <el-table-column label="创建时间">
        <template slot-scope="scope">
          <span>{{ scope.row.add_time | dateFilter }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
/* eslint-disable */
import Vue from 'vue'
import moment from 'moment'
Vue.filter('dateFilter', res => {
  return moment(res).format('YYYY-MM-DD')
})

export default {
  data () {
    return {
      goodsData: [{
        goods_name: 'TV',
        goods_price: '1000',
        goods_number: '12',
        add_time: '2019'
      }]
    }
  },
  created () {
    this.loadGoodsData()
  },
  methods: {
    // 加载商品数据
    async loadGoodsData () {
      let res = await this.$axios.get('goods', {
        params: {
          pagenum: 1,
          pagesize: 4
        }
      })
      console.log(res);
      this.goodsData = res.data.data.goods
    },
    // 跳转到添加商品页面
    go2goodAdd () {
      this.$router.push('/goods-add')
    }
  },
}
</script>

<style>
</style>
